<table id="dg_BaseQuery" class="easyui-datagrid" 
		data-options="
			iconCls: 'icon-edit',
			singleSelect: true,
			method:'get',
			fit:false,
			border:false, 
			rownumbers:false,
			onClickCell: onClickCell,
            toolbar:[{
				text: BUTTON_TITLE.ADD,
				width:60,
				iconCls: 'icon-add',
				handler: function(){
					query_addNew();
				}
			},{
				text: BUTTON_TITLE.REMOVE,
				width:60,
				iconCls: 'icon-remove',
				handler: function(){
					removeit($('#dg_BaseQuery'));
				}
			}]
		">
	<thead>
		<tr>
	        <th data-options="field:'brackets_l', width:40, editor:{
	            type:'combobox',options:{valueField:'key',textField:'key',editable:false,
	            data:[{key:'&nbsp'},{key:'('},{key:'(('},{key:'((('}]}
	            }">{$parenthesis}</th>
	        <th data-options="field:'fld_name', width:150, hidden:true">_field</th>
	        <th data-options="field:'fld_text', width:150">{$field}</th>
	        <th data-options="field:'comparison', width:80, editor:{type:'combobox',
	            options:{valueField:'key',textField:'val',required:true,editable:false,url:'/OA/Admin/Base/getOperator'}
	            }">{$comparison}</th>
	        <th data-options="field:'_value', width:150, hidden:true">_value</th>
	        <th data-options="field:'value', width:150">{$value}</th>
	        <th data-options="field:'brackets_r', width:40, editor:{type:'combobox',
	            options:{valueField:'key',textField:'key',editable:false,
	            data:[{key:'&nbsp'},{key:')'},{key:'))'},{key:')))'}]}
	            }">{$parenthesis}</th>
	        <th data-options="field:'logic', width:50, editor:{type:'combobox',
	            options:{valueField:'key',textField:'key',editable:false,
	            data:[{key:'&nbsp'},{key:'and'},{key:'or'}]}
	            }">{$operator}</th>
	    </tr>
	</thead>
</table>
<script type="text/javascript">
	//根据参数查询
	function getQueryRows () {
		var dg = $('#dg_BaseQuery');
		if (endEditing(dg)){
			var rows = dg.datagrid('getChanges');
			return rows;
		}else return null;
	}
	//添加新行
	function query_addNew () {
		$dg = $('#dg_BaseQuery');
		if(endEditing($dg)){
			var rows = $dg.datagrid('getRows');
            var i = rows == null ? 0 : rows.length;
            if (i > 0) {
                var lastrow = rows[i - 1];
                if (lastrow.fld_name == null || lastrow.comparison == null || lastrow.value == null || lastrow.logic == null) {
                    $.messager.alert("operation tips", "The pre condition is not complete", "error");
                    return;
                }
            }
            $dg.datagrid('appendRow', {});
		}
	}
	//加载查询条件
	function loadQueryParameters (mid) {
		$dg = $('#dg_BaseQuery');
		$dg.datagrid('appendRow', {});

		$dg.datagrid('addEditor',{field: 'fld_text', 
			editor: {
				type: 'combobox',
				options:{
					editable: false,
					valueField: 'fld_name',
					textField: 'fld_text',
					url: '/OA/Admin/Base/getQueryFields?mid='+mid,
					method: 'get',
					required: true,
					onSelect: addValueEditor
				}
			}
		})
	}
	//动态生成Editor
	function addValueEditor (record) {
		$dg = $('#dg_BaseQuery');
		var editIndex = $dg.attr('editIndex');
		$dg.datagrid('endEdit', editIndex);
		$dg.datagrid('updateRow', { index: editIndex, row: { fld_name: record.fld_name, fld_text: record.fld_text, comparison: '=' } });
		var fld_type = record.fld_type;
		switch(fld_type){
			case 1:
			break;
			default:
				$dg.datagrid('addEditor',{field: 'value',
					editor:{
						type: 'textbox',
						options: {required: true, validType:'notempty'}
					}
				})
			break;
		}
	}
</script>